#!/usr/bin/env coffee

import {cpus} from 'os'
import Pool from '@rmw/pool'
import Rust from '@rmw/rust'
import worker from '@rmw/worker'

{blake3_file} = Rust

POOL = Pool Math.max(Math.round(cpus().length/2), 1)

thread_hash = worker (fp)=>
  {blake3_file} = require '@rmw/rust'
  blake3_file(fp)

export default (fp,size)=>
  if size < 524288
    blake3_file(fp)
  else
    POOL =>
      console.log 'hashing',fp
      thread_hash(fp)
